<template>
	<div class="search_body">
		<div class="search_input">
			<div class="search_input_wrapper">
				<i class="fa fa-search"></i>
				<input class="search" type="text" v-model="searchString" placeholder="请输入电影名称"/>
			</div>
		</div>
		<div class="search_result">
			<h3>电影/电视剧/综艺</h3>
			<ul>
				<li v-for="item in searchMovie" :key="item.id">
					<div class="pic_show"><img :src="item.url"/></div>
					<div class="info_list">
						<h2>{{item.name}}</h2>
						<p>主演：{{item.actor}}</P>
						<p class="status">{{item.status}}</p >
					</div>
				
				</li>
			</ul>
		</div>
	</div>
</template>

<script>
	export default {
		name:'Search',
		data(){
				return{
				
			    searchString:"",
				commingMovieList:[],
				NowPlayingList:[],
				}
			},
		created(){
			this.getCommingData();
			this.getPlayingData();
		},
		computed:{
			searchMovie: function () {
				var movies_array = this.NowPlayingList.concat(this.commingMovieList),
					searchString = this.searchString;


				if(!searchString){
					return this.NowPlayingList;
				}

				searchString = searchString.trim().toLowerCase();
				movies_array =movies_array.filter(function(item){
					if(item.name.toLowerCase().indexOf(searchString) !== -1){
						return item;
					}
				})

				// 返回过来后的数组
				return movies_array;;
			}
		},
		methods:{
			
			getCommingData(){
				var that =this;
				axios.get('/mock/CommingSoon.json')
				  .then(function (response) {
				    console.log(response);
					if(response.status == 200){
						if(response.data && response.data.commingMovieList){
							that.commingMovieList=response.data.commingMovieList;
						}
					}
				  })
				  .catch(function (error) {
				    console.log(error);
				  });
			},
			getPlayingData(){
				var that =this;
				axios.get('/mock/NowPlaying.json')
				  .then(function (response) {
				    console.log(response);
					if(response.status == 200){
						if(response.data && response.data.NowPlayingList){
							that.NowPlayingList=response.data.NowPlayingList;
						}
					}
				  })
				  .catch(function (error) {
				    console.log(error);
				  });
		}
		}
	}
</script>

<style scoped="scoped">
	.search_result .info_list .status{
		color:#faaf00;
		font-size: 14px;
	}
	.search_result ul{
		margin: 0 12px;
		overflow: hidden;

	}
	.search_result ul li {
		margin-top: 12px;
		display: flex;
		align-items: center;
		border-bottom: 1px solids e6e6e6;
		padding-bottom: 10px;
	}
	.search_result .pic_show{
		width: 64px ;
		height: 90px;
	}
	.search_result .pic_show img{
		width: 100%;
	}
	.search_result .info_list{
		margin-left:10px ;
		flex: 1;
		position: relative;
	}
	.search_result .info_list h2{
	font-size: 17px ;
	line-height: 24px;
	width: 150px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	}
	.search_result .info_list p{
		font-size:  10px;
		color: #666;
		line-height: 22px;
		width: 200px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.search_body{
	width: 100%;
	position: absolute;
	top: 100px;
	bottom: 45px;
	flex: 1;
	overflow: auto;
	}
	.search_body .search_input{
		padding: 8px 10px;
		background-color: #f5f5f5;
		border-bottom: 1px solid #e5e5e5;
	}
	.search_body .search_input_wrapper{
		padding: 0 10px;
		border: 1px solid #E6E6E6;
		border-radius: 5px;
		background-color: #fff;
		display: flex;
	}
	.search_body .search_input_wrapper i{
		font-size: 16px;
		padding: 4px 0;
	}
	.search_body .search_input_wrapper input{
		border: none;
		font-size: 13px;
		color: #999;
		padding: none;
	}
	.search_body .search_result h3{
		font-size: 15px;
		color: #999;
		padding: 9px 15px;
		border-bottom: 1px solid #E6E6E6;
	}
	.search_body .search_result li{
		border-bottom: 1px #c9c9c9 dashed ;
		padding: 10px 15px;
		box-sizing: border-box;
		display: flex;
	}
	
	
	
	.search_body .search_result .info p:nth-of-type(1) span:nth-of-type(1){
		font-size: 18px;
		flex: 1;
	}
	.search_body .search_result .info p:nth-of-type(1) span:nth-of-type(2){
		font-size: 16px;
		color: #fc7103;
	}
	.search{
		width: 100%;
	}
	
</style>
